#pragma once
#include "pch.h"
#include "Filter.h"
#include "Pipe.h"
#include "FilterPipeConfig.h"
#include "Common.h"
#include <semaphore>
namespace AutomatedSurfaceReconstruction
{
	extern std::counting_semaphore<100> OutputSemaphore;
	extern std::string OutputPath;
	class CFilterPipeSystem
	{
	public:
		CFilterPipeSystem();
		~CFilterPipeSystem();
		bool pushData2FilePool(std::pair<std::pair<std::string, CGALPointSetType>, CGALPointSetType>& vPointSet2DXFRoad);
		std::string setMaxUsedThread();
		bool organizeExternalInputBuffer();
		std::string getFinishedThreadOutputPath();

	private:
		const int m_SourceFilterIndex = 0;
		const int m_DstFilterIndex = 7;
		const int m_ProcessFileNum = 6;
		const std::string m_FilterPipeConfigFileName = std::string("FilterPipe.xml");
		size_t m_MaxUsedThread;
		hiveSystem::CFilterPipeSystem m_ReconstructSystem;
		std::map< int, std::uint32_t> m_ID2Handle;
		std::deque<std::pair<std::pair<std::string, CGALPointSetType>, CGALPointSetType>> m_FilePool;
		std::vector<SFilter> m_FilterSet;
		std::vector<SPipe> m_PipeSet;
		std::vector<std::optional<std::uint8_t>> m_InputBufferHandle;
		std::vector<std::optional<std::uint8_t>> m_OutputBufferHandle;
		std::vector<hiveSystem::CConcurrentQueue<std::pair<std::pair<std::string, CGALPointSetType>, CGALPointSetType>>*> m_pExternalInputBuffer;
		std::vector<hiveSystem::CConcurrentQueue<std::string>*> m_pExternalOutputBuffer;

		void __initXML();
		void __initFilter();
		void __initPipe();
		void __initExternalBuffer();

	};
}